<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    request.setAttribute("basePath",basePath);
%>
<%@ include file="/resources/js/easyui/taglibs.jsp"%>
<%@ include file="/resources/js/wechat/_wechatui.jsp"%>
<%@ include file="/resources/js/easyui/_viewJS.jsp"%>
<!DOCTYPE>
<html>
<head>
    <title>设备查询</title>
</head>
<body>
<div class="loading"></div>
<!-- header -->
<header>
    <a href="javascript:history.go(-1);" class="top_fh">搜索</a>
</header>
<!-- header end -->

<div class="page search_page">
    <div class='search_inner'>
        <div class="select">
            <select id="placeId" style="width:100%;background: #fff;appearance:none; -moz-appearance: none; -webkit-appearance:none; ">
                <option value="0" selected="selected">全部场地</option>
                <c:forEach items="${placeList}" var="place">
                    <option value="${place.placeid}">${place.address}</option>
                </c:forEach>
            </select>
        </div>
        <div class="select">
            <select id="deviceId" style="width:100%;background: #fff;appearance:none; -moz-appearance: none; -webkit-appearance:none; ">
                <option value="0">全部设备</option>
                <c:forEach items="${deviceList}" var="device">
                    <option value="${device.deviceId}" >${device.address} - ${device.deviceName}</option>
                </c:forEach>
            </select>
        </div>
        <div class="select">
            <input type="text" id="deviceShortCode" placeholder="设备简码"/>
        </div>
    </div>
    <div class="search_button"><a href="javascript:;" id="searchBtn">搜索</a></div>
</div>
</body>

<script type="application/javascript">

    $("#placeId").change(function(){
        $.ajax({
            url:'${basePath}wechat/operate/search/queryPlace2Device',
            type : 'POST',
            data : {'placeId':$("#placeId").val()},
            error: function (response) {
                ViewHelper.func.ajaxWechatErrorMessage(response);
            },
            success: function (ret) {
                $("#deviceId option").remove();
                if(ret.result) {
                    if(ret.deviceList.length>0){
                        $("#deviceId").append('<option value="0" selected="selected">全部设备</option>');
                        $.each(ret.deviceList,function(n,value) {
                            $("#deviceId").append('<option value="'+value.deviceId+'">'+value.address+' - '+value.deviceName+'</option>');
                        });
                    }else{
                        $("#deviceId").append('<option value="0" selected="selected">全部设备</option>');
                    }
                }else{
                    alert(ret.info);
                }
            }
        });

    });

    $("#searchBtn").click(function(){
        var placeId = $("#placeId").val();
        var deviceId = $("#deviceId").val();
        var deviceShortCode = $("#deviceShortCode").val();
        $.ajax({
            url:'${basePath}wechat/operate/search/queryDevices',
            type : 'POST',
            data : {"placeId":placeId, "deviceId":deviceId, "deviceShortCode":deviceShortCode},
            error: function (response) {
                ViewHelper.func.ajaxWechatErrorMessage(response);
            },
            success: function (ret) {
                if(ret.result) {
                    window.location = "${basePath}wechat/operate/search/deviceView?placeId="+ret.placeId+"&deviceIds="+ret.deviceIds;
                }else{
                    window.location = "${basePath}wechat/operate/search/searchDeviceView";
                }
            }
        });
    });

</script>


</html>